package com.zmn.mcc.admin.controller.staff.staffarchives;


import com.zmn.mcc.common.constant.StaffArchivesConsts;
import com.zmn.mcc.common.dictionary.StaffArchivesDict;
import com.zmn.mcc.model.dto.pic.ImageReslutDTO;
import com.zmn.mcc.model.entity.staff.McStaff;
import com.zmn.mcc.model.entity.staff.staffarchives.StaffArchives;
import com.zmn.mcc.services.interfaces.staff.staffarchives.StaffArchivesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 员工档案基础查询Controller
 *
 * @author tanghongjun
 * @since 2020-05-14 11:15:18
 */
@RestController
@RequestMapping("/staff/staffarchives/")
public class StaffArchivesListController extends StaffArchivesBaseController {

    private Logger logger = LoggerFactory.getLogger(StaffArchivesListController.class);

    @Resource
    private StaffArchivesService staffArchivesService;

    /**
     * 信息
     */
    @RequestMapping("/addEditView")
//    @RequiresPermissions("staff/staffarchives/addEditView.action")
    public ModelAndView addEditView(@RequestParam(value = "staffId", defaultValue = "0") Integer staffId) {

        McStaff staff = staffService.findByKey(staffId);
        StaffArchives staffArchives = staffArchivesService.findByStaffId(staffId);
        if (Objects.isNull(staffArchives)) {
            staffArchives = new StaffArchives();
            staffArchives.setStaffId(staffId);
        }

        ModelAndView mav = new ModelAndView("staff/staffarchives/detail");

        mav.addObject("staffArchives", staffArchives);
        mav.addObject("residenceTypes", StaffArchivesDict.getResidenceTypeList());
        mav.addObject("eduList", StaffArchivesDict.getHighestEduList());
        mav.addObject("marriageList", StaffArchivesDict.getMarriageStatusList());
        mav.addObject("politicalList", StaffArchivesDict.getPoliticalStatusList());
        mav.addObject("obj", staff);
        mav.addObject("flag", 2);

        return mav;
    }

    /**
     * 描述: 文件上传
     *
     * @param file      文件对象
     * @param timestamp 时间戳
     * @param elemId    元素id
     * @return com.zmn.common.dto.ImageUploadDTO
     * @author wangjie
     * @modifier tanbiao 20190930 前台后台产品代码整理
     * @since 2018/10/22 10:56
     */
    @RequestMapping(value = "uploaderImage")
    @ResponseBody
    public ImageReslutDTO uploaderStaffArchivesImage(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "timestamp") String timestamp
            , @RequestParam(value = "elemId") String elemId) {

        return super.uploaderImage(file, StaffArchivesConsts.STAFF_ARCHIVES_UPLOAD_IMAGES_PATH, elemId, timestamp);
    }

}
